<template>
  <div id="wrapper">
    <div id="bg" />
    <div id="overlay" />
    <div id="main" class="login-container">
      <el-form ref="loginForm" :rules="rules" :model="loginForm" class="login-form" label-position="left">
        <div style="display: flex;">
          <img class="logo" src="./img/logo.png" />
        </div>
        <div style="padding: 10px; font-size: 32px;">车务调车作业安全管控系统</div>
        <el-form-item prop="userName">
          <!-- eslint-disable-next-line -->
          <span style="margin-left:25px; margin-top:8px; float:left;" class="fa fa-user fa-2x"></span>
          <el-input v-model="loginForm.userName" type="text" placeholder="请输入用户名"
                    style="font-size:20px;max-length:11;min-length:11;" />
        </el-form-item>
        <el-form-item prop="password">
          <span style="margin-left:25px; margin-top:8px; float:left;" class="fa fa-lock fa-2x" />
          <el-input v-model="loginForm.password" :type="pwdType" placeholder="请输入密码"
                    style="font-size:20px;width:80%;min-length:6;max-length:6;" />
          <span :class="pwdClassType" style="margin-right:5px;font-size:20px" @click="showPwd" />
        </el-form-item>
        <el-form-item>
          <el-button :loading="loading" type="primary" class="login-button" @click.native.prevent="handleLogin">
            登 录
          </el-button>
        </el-form-item>
      </el-form>
      <div class="bottom-info">
        <div style="display:flex; justify-content:center; align-items:center;">
          <div style="float: left; margin-left: 0%;"><img class="bottom-logo" src="./img/train-logo.png" /></div>
          <div style="float: left; font-size: 22px; margin: 10px 0;">卡斯柯信号有限公司</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  components: {},
  data() {
    return {
      loginForm: {
        userName: '',
        password: ''
      },
      rules: {
        userName: [
          { required: true, message: '请输入登录需要的用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      },
      loading: false,
      pwdType: 'password',
      redirect: undefined,
      pwdClassType: 'fa fa-eye-slash fa-x'
    }
  },
  computed: {},
  watch: {
    $route: {
      handler: function (route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  mounted() {
    window.addEventListener('keyup', this.onSubmit, false)
  },
  destroyed() {
    // //向全局申请取消订阅频道（订阅请求，订阅信息）
    // this.$bus.$emit('Unsubscribe', require)
    // // 关闭接收数据
    // this.sockets.unsubscribe('test_zbl')
  },
  methods: {
    onSubmit(e) {
      if (e.keyCode == 13 || e.keyCode == 100) {
        this.handleLogin();
      }
    },
    showPwd() {
      this.pwdType = this.pwdType === 'password' ? '' : 'password'
      this.pwdClassType = this.pwdType === 'password' ? 'fa fa-eye-slash fa-x' : 'fa fa-eye fa-x'
    },
    handleLogin() {
      this.$refs['loginForm'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$store
            .dispatch('user/login', this.loginForm)
            .then(() => {
              console.log(this.redirect);
              this.$router.push({ path: '/gis/index' })
              this.loading = false
              this.$message.success('登录成功！')
            })
            .catch(msg => {
              this.$message.error(msg)
              this.loading = false
            })
        } else {
          this.$message.error('请检查用户名和密码！')
          return false
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
$bg: #2d3a4b;

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: #000;
      height: 47px;

      &:-webkit-autofill {
        -webkit-box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: #fff !important;
      }
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}
</style>

<style rel="stylesheet/scss" lang="scss" scoped>
/* Wrapper */
@-moz-keyframes wrapper {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@-webkit-keyframes wrapper {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@-o-keyframes wrapper {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@-ms-keyframes wrapper {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@keyframes wrapper {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

#wrapper {
  -moz-animation: wrapper 3s forwards;
  -webkit-animation: wrapper 3s forwards;
  -o-animation: wrapper 3s forwards;
  -ms-animation: wrapper 3s forwards;
  animation: wrapper 3s forwards;
  height: 100%;
  left: 0;
  opacity: 0;
  position: fixed;
  top: 0;
  width: 100%;
}

/* BG */
#bg {
  -moz-animation: bg 60s linear infinite;
  -webkit-animation: bg 60s linear infinite;
  -o-animation: bg 60s linear infinite;
  -ms-animation: bg 60s linear infinite;
  animation: bg 60s linear infinite;
  -moz-backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  -o-backface-visibility: hidden;
  -ms-backface-visibility: hidden;
  backface-visibility: hidden;
  -moz-transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  -o-transform: translate3d(0, 0, 0);
  -ms-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
  background-color: #348cb2;
  background-image: url('./img/bg.png');
  background-position: center;
  background-repeat: repeat-x;
  background-size: 100% 100%;
  height: 100%;
  left: 0;
  opacity: 1;
  position: fixed;
  top: 0;
}

@-moz-keyframes bg {
  0% {
    -moz-transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    -o-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }

  100% {
    -moz-transform: translate3d(-2250px, 0, 0);
    -webkit-transform: translate3d(-2250px, 0, 0);
    -o-transform: translate3d(-2250px, 0, 0);
    -ms-transform: translate3d(-2250px, 0, 0);
    transform: translate3d(-2250px, 0, 0);
  }
}

@-webkit-keyframes bg {
  0% {
    -moz-transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    -o-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }

  100% {
    -moz-transform: translate3d(-2250px, 0, 0);
    -webkit-transform: translate3d(-2250px, 0, 0);
    -o-transform: translate3d(-2250px, 0, 0);
    -ms-transform: translate3d(-2250px, 0, 0);
    transform: translate3d(-2250px, 0, 0);
  }
}

@-o-keyframes bg {
  0% {
    -moz-transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    -o-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }

  100% {
    -moz-transform: translate3d(-2250px, 0, 0);
    -webkit-transform: translate3d(-2250px, 0, 0);
    -o-transform: translate3d(-2250px, 0, 0);
    -ms-transform: translate3d(-2250px, 0, 0);
    transform: translate3d(-2250px, 0, 0);
  }
}

@-ms-keyframes bg {
  0% {
    -moz-transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    -o-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }

  100% {
    -moz-transform: translate3d(-2250px, 0, 0);
    -webkit-transform: translate3d(-2250px, 0, 0);
    -o-transform: translate3d(-2250px, 0, 0);
    -ms-transform: translate3d(-2250px, 0, 0);
    transform: translate3d(-2250px, 0, 0);
  }
}

@keyframes bg {
  0% {
    -moz-transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    -o-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }

  100% {
    -moz-transform: translate3d(-2250px, 0, 0);
    -webkit-transform: translate3d(-2250px, 0, 0);
    -o-transform: translate3d(-2250px, 0, 0);
    -ms-transform: translate3d(-2250px, 0, 0);
    transform: translate3d(-2250px, 0, 0);
  }
}

#bg {
  background-size: 1700px auto;
  width: 6750px;
}

/* Overlay */
@-moz-keyframes overlay {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@-webkit-keyframes overlay {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@-o-keyframes overlay {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@-ms-keyframes overlay {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@keyframes overlay {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

#overlay {
  -moz-animation: overlay 1.5s 1.5s forwards;
  -webkit-animation: overlay 1.5s 1.5s forwards;
  -o-animation: overlay 1.5s 1.5s forwards;
  -ms-animation: overlay 1.5s 1.5s forwards;
  animation: overlay 1.5s 1.5s forwards;
  background-attachment: fixed, fixed;
  background-image: url('./img/overlay-pattern.png'), url('./img/overlay.svg');
  background-position: top left, center center;
  background-repeat: repeat, no-repeat;
  background-size: auto, cover;
  height: 100%;
  left: 0;
  opacity: 0;
  position: fixed;
  top: 0;
  width: 100%;
}

/* Main */

#main {
  height: 100%;
  left: 0;
  position: fixed;
  text-align: center;
  top: 0;
  width: 100%;
}

#main:before {
  display: inline-block;
  height: 100%;
  margin-right: 0;
  vertical-align: middle;
  width: 1px;
}

.login-form {
  position: absolute;
  left: 50%;
  width: 50%;
  top: 45%;
  transform: translate(-50%, -50%);
  min-width: 400px;
  max-width: 600px;
  height: auto !important;
  min-height: 400px;
  background-color: rgba(255, 255, 255, 0.9);
  padding: 50px 20px 10px 20px;
  font-size: 24px;
  font-weight: 600;
  border-radius: 10px;
  align-items: center;

}

.svg-container {
  padding: 6px 5px 6px 15px;
  vertical-align: middle;
  width: 30px;
  display: inline-block;
}

.logo {
  width: 174.357px;
  height: 80px;
  margin: 0 auto 15px auto;
}

.show-pwd {
  position: absolute;
  right: 10px;
  top: 7px;
  font-size: 16px;
  cursor: pointer;
  user-select: none;
}

.login-button {
  font-size: 19px;
  width: 100%;
}

.bottom-logo {
  width: 44px;
  height: 44px;
}

.bottom-info {
  position: fixed;
  bottom: 10px;
  width: 100%;
  margin: 0 auto;
  color: #ffffff;
  font-size: 20px;
}</style>
